Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add << merge key to "spread" mappings into a mapping. #69

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cowboyd
Copy link
Member

@cowboyd cowboyd commented Jan 27, 2023

Motivation

In order to gracefully compose data structures, you need a way to insert an entire set of mappings into another at a single place. This is equivalent to the javascript ... operator.

YAML allows support for this with the language independent type "merge-key" feature.

Approach

This implements the spec here https://yaml.org/type/merge.html

Thus evaluating this example:

composed:
  <<:
    one: 1
    two: 2
  <<:
    three: 3
    four: 4
  <<:
    -
      five: 5
    -
      six: 6

is:

composed:
  one: 1
  two: 2
  three: 3
  four: 4
  five: 5
  six: 6

Learning

Although ubiquitous, this syntax is officially deprecated and will be replaced by something else in YAML 1.3 but nobody is for sure what that will be.

@cowboyd cowboyd requested a review from a team January 27, 2023 16:21
In order to gracefully compose data structures, you need a way to
insert an entire set of mappings into another at a single
place. This is equivalent to the javascript `...` operator.

YAML allows support for this with the language
independent type "merge-key"  feature.

This implements the spec here https://yaml.org/type/merge.html

Thus evaluating this example:

```yaml
composed:
  <<:
    one: 1
    two: 2
  <<:
    three: 3
    four: 4
  <<:
    -
      five: 5
    -
      six: 6
```

is:

```yaml
composed:
  one: 1
  two: 2
  three: 3
  four: 4
  five: 5
  six: 6
```

Although ubiquitous, this syntax is officially deprecated and will
be replaced by something else in YAML 1.3 but nobody is for sure what
that will be.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant